package cn.itcast.flink.trans;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Author itcast
 * Date 2022/1/13 9:14
 * Desc 实现两个相同数据类型的集合的合并
 */
public class UnionDemo {
    public static void main(String[] args) throws Exception {
        //todo 1. 获取流执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //todo 2. 设置并行度和参数
        env.setParallelism(1);
        //todo 3. 加载数据，两个数据流
        DataStreamSource<String> source1 = env.fromElements("hello", "world");
        DataStreamSource<String> source2 = env.fromElements("hello", "hadoop");
        DataStreamSource<String> source3 = env.fromElements("hello", "flink");
        //todo 4. 合并union两个数据流
        DataStream<String> result = source1.union(source2, source3);
        //todo 5. 打印输出
        result.print();
        //todo 6. 执行作业
        env.execute();
    }
}
